/*
 * @Description  : mock 数据
 * @Author       : Keyman
 * @Date         : 2025-11-04 16:18:57
 * @LastEditors  : Keyman
 * @LastEditTime : 2025-11-28 16:56:28
 */

import Mock from "mockjs";

const menuList = [
  {
    icon: "DashboardOutlined",
    label: "工作台",
    key: "/dashboard",
  },
  {
    icon: "TeamOutlined",
    label: "租户管理",
    key: "/users",
    children: [
      {
        icon: "UnorderedListOutlined",
        label: "租户列表",
        key: "/users/list",
      },
      {
        icon: "UserAddOutlined",
        label: "新增租户",
        key: "/users/add",
      },
    ],
  },
  {
    icon: "LaptopOutlined",
    label: "物业管理",
    key: "/estate",
    children: [
      {
        icon: "InsertRowLeftOutlined",
        label: "楼宇管理",
        key: "/estate/tenement",
      },
      {
        icon: "BankOutlined",
        label: "房间管理",
        key: "/estate/room",
      },
      {
        icon: "TruckOutlined",
        label: "车辆信息",
        key: "/estate/car",
      },
    ],
  },
  {
    icon: "ToolOutlined",
    label: "报修管理",
    key: "/repair",
  },
  {
    icon: "DollarOutlined",
    label: "财务管理",
    key: "/finance",
    children: [
      {
        icon: "ProfileOutlined",
        label: "合同管理",
        key: "/finance/contract",
      },
      {
        icon: "FrownOutlined",
        label: "合同详情",
        key: "/finance/surrender",
      },
      {
        icon: "FileTextOutlined",
        label: "账单管理",
        key: "/finance/bill",
      },
    ],
  },
  {
    icon: "TransactionOutlined",
    label: "招商管理",
    key: "/merchants",
  },
  {
    icon: "FundProjectionScreenOutlined",
    label: "运营管理",
    key: "/operation",
    children: [
      {
        icon: "FundViewOutlined",
        label: "运营总览",
        key: "/operation/all",
      },
      {
        icon: "ReadOutlined",
        label: "文章发布",
        key: "/operation/article",
      },
      {
        icon: "CommentOutlined",
        label: "内容评论",
        key: "/operation/comments",
      },
    ],
  },
  {
    icon: "ToolOutlined",
    label: "设备管理",
    key: "/equipment",
  },
  {
    icon: "ThunderboltOutlined",
    label: "能源消耗",
    key: "/energy",
  },
  {
    icon: "SettingOutlined",
    label: "系统设置",
    key: "/settings",
  },
  {
    icon: "UserOutlined",
    label: "个人中心",
    key: "/personal",
  },
];

const userMenuList = [
  {
    icon: "DashboardOutlined",
    label: "工作台",
    key: "/dashboard",
  },
  {
    icon: "TeamOutlined",
    label: "租户管理",
    key: "/users",
    children: [
      {
        icon: "UnorderedListOutlined",
        label: "租户列表",
        key: "/users/list",
      },
      {
        icon: "UserAddOutlined",
        label: "新增租户",
        key: "/users/add",
      },
    ],
  },
  {
    icon: "LaptopOutlined",
    label: "物业管理",
    key: "/estate",
    children: [
      {
        icon: "InsertRowLeftOutlined",
        label: "楼宇管理",
        key: "/estate/tenement",
      },
      {
        icon: "BankOutlined",
        label: "房间管理",
        key: "/estate/room",
      },
      {
        icon: "TruckOutlined",
        label: "车辆信息",
        key: "/estate/car",
      },
    ],
  },
  {
    icon: "ToolOutlined",
    label: "报修管理",
    key: "/repair",
  },
  {
    icon: "ToolOutlined",
    label: "设备管理",
    key: "/equipment",
  },
  {
    icon: "ThunderboltOutlined",
    label: "能源消耗",
    key: "/energy",
  },
  {
    icon: "UserOutlined",
    label: "个人中心",
    key: "/personal",
  },
];

const managerMenuList = [
  {
    icon: "DashboardOutlined",
    label: "工作台",
    key: "/dashboard",
  },
  {
    icon: "TeamOutlined",
    label: "租户管理",
    key: "/users",
    children: [
      {
        icon: "UnorderedListOutlined",
        label: "租户列表",
        key: "/users/list",
      },
      {
        icon: "UserAddOutlined",
        label: "新增租户",
        key: "/users/add",
      },
    ],
  },
  {
    icon: "LaptopOutlined",
    label: "物业管理",
    key: "/estate",
    children: [
      {
        icon: "InsertRowLeftOutlined",
        label: "楼宇管理",
        key: "/estate/tenement",
      },
      {
        icon: "BankOutlined",
        label: "房间管理",
        key: "/estate/room",
      },
      {
        icon: "TruckOutlined",
        label: "车辆信息",
        key: "/estate/car",
      },
    ],
  },
  {
    icon: "ToolOutlined",
    label: "报修管理",
    key: "/repair",
  },
  {
    icon: "TransactionOutlined",
    label: "招商管理",
    key: "/merchants",
  },
  {
    icon: "FundProjectionScreenOutlined",
    label: "运营管理",
    key: "/operation",
    children: [
      {
        icon: "FundViewOutlined",
        label: "运营总览",
        key: "/operation/all",
      },
      {
        icon: "ReadOutlined",
        label: "文章发布",
        key: "/operation/article",
      },
      {
        icon: "CommentOutlined",
        label: "内容评论",
        key: "/operation/comments",
      },
    ],
  },
  {
    icon: "ToolOutlined",
    label: "设备管理",
    key: "/equipment",
  },
  {
    icon: "ThunderboltOutlined",
    label: "能源消耗",
    key: "/energy",
  },
  {
    icon: "SettingOutlined",
    label: "系统设置",
    key: "/settings",
  },
  {
    icon: "UserOutlined",
    label: "个人中心",
    key: "/personal",
  },
];

// const customizeMenuList = [
//   {
//     icon: "DashboardOutlined",
//     label: "工作台",
//     key: "/dashboard",
//   },
//   {
//     icon: "TeamOutlined",
//     label: "租户管理",
//     key: "/users",
//     children: [
//       {
//         icon: "UnorderedListOutlined",
//         label: "租户列表",
//         key: "/users/list",
//       },
//     ],
//   },
//   {
//     icon: "LaptopOutlined",
//     label: "物业管理",
//     key: "/estate",
//     children: [
//       {
//         icon: "InsertRowLeftOutlined",
//         label: "楼宇管理",
//         key: "/estate/tenement",
//       },
//     ],
//   },
//   {
//     icon: "ToolOutlined",
//     label: "报修管理",
//     key: "/repair",
//   },
//   {
//     icon: "ToolOutlined",
//     label: "设备管理",
//     key: "/equipment",
//   },
//   {
//     icon: "ThunderboltOutlined",
//     label: "能源消耗",
//     key: "/energy",
//   },
//   {
//     icon: "UserOutlined",
//     label: "个人中心",
//     key: "/personal",
//   },
// ];

Mock.setup({
  timeout: "250-800",
});

Mock.Random.extend({
  phone: function () {
    const phonePrefix = ["13", "14", "15", "16", "17", "18", "19"];
    return this.pick(phonePrefix) + Mock.mock(/\d{9}/);
  },
});

// 登录接口
Mock.mock("https://www.demo.com/login", "post", (options: any) => {
  const { username, password } = JSON.parse(options.body);
  if (username === "admin" && password === "admin123123") {
    return {
      code: 200,
      message: "登录成功",
      data: {
        username: "admin",
        token: "mocktoken123456admin",
      },
    };
  } else if (username === "manager" && password === "manager123123") {
    return {
      code: 200,
      message: "登录成功",
      data: {
        username: "manager",
        token: "mocktoken123456manager",
      },
    };
  } else if (username === "user" && password === "user123123") {
    return {
      code: 200,
      message: "登录成功",
      data: {
        username: "user",
        token: "mocktoken123456user",
      },
    };
  } else {
    return {
      code: 401,
      message: "用户或密码错误",
      data: "",
    };
  }
});

// 菜单项接口 (根据角色返回菜单项)
Mock.mock("https://www.demo.com/menu", "get", () => {
  const token = sessionStorage.getItem("token");
  if (token === "mocktoken123456admin") {
    return {
      code: 200,
      message: "登录成功",
      data: menuList,
    };
  } else if (token === "mocktoken123456manager") {
    return {
      code: 200,
      message: "登录成功",
      data: managerMenuList,
    };
  } else if (token === "mocktoken123456user") {
    return {
      code: 200,
      message: "登录成功",
      data: userMenuList,
    };
  } else {
    return {
      code: 200,
      message: "失败",
      data: [],
    };
  }
});

Mock.mock("https://www.demo.com/energyData", "get", () => {
  return {
    code: 200,
    message: "数据获取成功",
    data: [
      { name: "煤", data: [120, 132, 101, 134, 90, 230, 210] },
      { name: "气", data: [220, 182, 191, 234, 290, 330, 310] },
      { name: "油", data: [150, 232, 201, 154, 190, 330, 410] },
      { name: "电", data: [320, 332, 301, 334, 390, 330, 320] },
      { name: "热", data: [820, 932, 901, 934, 1290, 1330, 1320] },
    ],
  };
});

Mock.mock("https://www.demo.com/userlist", "post", (options: any) => {
  const { pageSize } = JSON.parse(options.body);
  return {
    code: 200,
    message: "数据获取成功",
    data: Mock.mock({
      [`list|${pageSize}`]: [
        {
          id: "@string('number', 10)",
          name: "@cname",
          "status|1": ["1", "2", "3"],
          creditCode: "@string('number',18)",
          email: "@email",
          "bussiness|1": [
            "制造业",
            "医疗",
            "新媒体",
            "互联网",
            "新能源",
            "物流",
            "电商",
          ],
          tel: "@phone",
          industryNum: "@string('number',15)",
          organizationCode: "@string('upper',9)",
          legalPerson: "@cname",
        },
      ],
      total: 12546,
    }),
  };
});

//删除企业
Mock.mock("https://www.demo.com/deleteUser", "post", (options: any) => {
  const { id } = JSON.parse(options.body);
  console.log("删除企业", id);
  return {
    code: 200,
    message: "成功",
    data: "操作成功",
  };
});

//批量删除企业
Mock.mock("https://www.demo.com/batchDeleteUser", "post", (options: any) => {
  const { ids } = JSON.parse(options.body);
  console.log("ids", ids);
  return {
    code: 200,
    message: "成功",
    data: "操作成功",
  };
});

//编辑企业
Mock.mock("https://www.demo.com/editUser", "post", (options: any) => {
  console.log("编辑企业收到参数", JSON.parse(options.body));
  return {
    code: 200,
    message: "成功",
    data: "操作成功",
  };
});

//获取房间列表的接口
function generateRooms() {
  const rooms = [];
  for (let i = 0; i < 50; i++) {
    const floor = 1 + Math.floor(i / 6); // 每6个房间一层
    const roomNumber = floor * 100 + (101 + (i % 6)); // 计算房间号
    rooms.push({
      roomNumber,
      decorationType: Mock.Random.pick(["毛坯", "精装"]),
      area: Mock.Random.integer(70, 300),
      unitPrice: Mock.Random.integer(1, 3),
      src: "https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png",
    });
  }
  return rooms;
}

Mock.mock("https://www.demo.com/roomList", "post", (options: any) => {
  console.log("收到房间id", JSON.parse(options.body).roomid);
  return {
    code: 200,
    message: "成功",
    data: {
      rooms: generateRooms(),
    },
  };
});
